/**
 * 使用步骤
 * 1.下载安装mongoose
 * npm i mongoose --save
 *
 * 2. 引入mongoose
 * var mongoose = require("mongoose");
 *
 * 3. 启动并连接mongodb
 * const mongoose = require('mongoose');
 mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true, useUnifiedTopology: true});

 const Cat = mongoose.model('Cat', { name: String });

 const kitty = new Cat({ name: 'Zildjian' });
 kitty.save().then(() => console.log('meow'));
 */

//1.引入
let mongoose = require("mongoose");

// 2.连接数据库
mongoose.connect("mongodb://127.0.0.1/test",{useNewUrlParser: true,useUnifiedTopology: true});

mongoose.connection.once("open",function (){
    console.log("数据库连接成功");
})

mongoose.connection.once("close",function (){
    console.log("数据库断开连接~~~");
})

// 断开数据库连接
mongoose.disconnect();



